﻿
using System.Collections;
using Microsoft.SharePoint;
namespace FTTXImportUtility.Utility
{
  class AlgorithmDefaultUtility
  {
    public static Hashtable GetDefaultRoadMap(SPList listTarget, SPList listSource)
    {
      var map = new Hashtable();

      foreach (SPField targetItem in listTarget.Fields)
      {
        if (!targetItem.ReadOnlyField && listSource.Fields.ContainsField(targetItem.Title))
        {
          //map[item.InternalName] = item.InternalName;

          SPField sourceItem = listSource.Fields[targetItem.Title];
          ItemTag itemTag = ConstrainItemTag(sourceItem, targetItem, false);
          map[targetItem.Id] = itemTag;
        }
      }

      return map;
    }


    public static ItemTag ConstrainItemTag(SPField sourceField, SPField targetField, bool ExtractTextOnlyFromLookUp)
    {
      var text = string.Format("{0} ({1}) -> {2} ({3})", sourceField.Title, sourceField.InternalName, targetField.Title, targetField.InternalName);

      ItemTag itemTag = new ItemTag { Text = text, TargetField = targetField, SourceField = sourceField, ExtractTextOnlyFromLookUp = ExtractTextOnlyFromLookUp };
      return itemTag;
    }
  }
}
